package fr.insee.sicape.format;

import fr.insee.sicape.bean.Reponse;

public class ColumnFormater implements Formater {

	private String missing;
	private String[] positions;
	
	public ColumnFormater(){}
	
	@Override
	public String format(Reponse reponse, String code, String chaine) {
		
		StringBuffer line = new StringBuffer(400); 
		
		int p1 = Integer.parseInt(positions[0]);
		for(int n = 1 ; n < p1 ; n ++){
			line.append(" ");
		}
		line.append(reponse.getInfoPassives());
		
		int p2 = Integer.parseInt(positions[1]);
		p2 = p2 - line.length();
		for(int n = 1 ; n < p2 ; n ++){
			line.append(" ");
		}
		line.append(code == null ? missing : code);
		
		int p3 = Integer.parseInt(positions[2]);
		if(p3 > 0){
			p3 = p3 - line.length();
			for(int n = 1 ; n < p3 ; n ++){
				line.append(" ");
			}
			line.append(chaine);
		}
		line.append("\n");
		
		return line.toString();
	}

	public String getMissing() {
		return missing;
	}

	public void setMissing(String missing) {
		this.missing = missing;
	}

	public String[] getPositions() {
		return positions;
	}

	public void setPositions(String[] positions) {
		this.positions = positions;
	}
}
